package com.geek.gkfgw.runner;

import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.web.client.RestTemplate;

/**
 * <h1>启动类。</h1><br/>
 *
 * <h1><br/><a href="https://u.geekbang.org/subject/arch3/100614201">Java 业务架构实战营：https://u.geekbang.org/subject/arch3/100614201</a></h1><br/><h1><a href="https://gitee.com/ylimhhmily/BizArchPracticeCamp">Java 业务架构实战营代码地址：https://gitee.com/ylimhhmily/BizArchPracticeCamp</a></h1><br/><h1><a href="https://u.geekbang.org/subject/java4th/1001148?source=app_share">高级 Java 工程体系课 2023 版：https://u.geekbang.org/subject/java4th/1001148?source=app_share</a></h1><br/><h1><a href="https://time.geekbang.org/column/intro/100312101?tab=catalog">Dubbo 源码剖析与实战：https://time.geekbang.org/column/intro/100312101?tab=catalog</a></h1>
 *
 * @author hmilyylimh
 * ^_^
 * @version 0.0.1
 * ^_^
 * @date 2022-02-13
 */
@Slf4j
@SpringBootApplication(scanBasePackages = {"com.geek.gkfgw"},
    exclude = {DataSourceAutoConfiguration.class, RedisAutoConfiguration.class}
)
@ImportResource({"classpath*:/spring/applicationContext*.xml"})
@EnableDiscoveryClient
@EnableFeignClients(basePackages = "com.geek.gkfgw.integration")
@EnableDubbo(scanBasePackages = "com.geek.gkfgw")
@EnableCaching
public class ApplicationRunner {

    /**
     * 测试使用的启动命令：
     * -Dserver.tomcat.max-threads=1 -Dserver.tomcat.max-connections=1 -Dserver.tomcat.accept-count=1 -Dserver.tomcat.min-spare-threads=1
     */

    public static void main(String[] args) {
        ConfigurableApplicationContext ctx = SpringApplication.run(ApplicationRunner.class, args);
        String serverPort = ctx.getEnvironment().getProperty("server.port");
        String appName = ctx.getEnvironment().getProperty("app.name");
        // System.out.println("【【【【【【 ApplicationRunner微服务 】】】】】】已启动");
        log.info("【【【【【【 ApplicationRunner微服务:{}:{} 】】】】】】已启动", appName, serverPort);
    }

    @LoadBalanced
    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }
}